package com.yjhb.android.sbz.v2.dialog

import android.app.Activity
import android.content.Intent
import android.text.method.LinkMovementMethod
import com.yjhb.android.sbz.R
import com.yjhb.android.sbz.activity.MainActivity
import com.yjhb.android.sbz.tool.DataSaveTool
import com.yjhb.android.sbz.tool.Tool
import com.jojo.android.zxlib.base.BaseDialog
import com.jojo.android.zxlib.tool.ZxSpanTool
import kotlinx.android.synthetic.main.dialog_privacy.*


/**
 *  创建者 zx
 *  创建时间 2021/7/8 13:37
 */
class PrivacyDialog(activity:Activity) : BaseDialog(activity) {

    override fun init() {
        setCancelable(false)
        window.attributes.width = -1
        pass_btn?.setOnClickListener {
            DataSaveTool.saveShowPrivacyTips(false)
            activity.startActivity(Intent(activity, MainActivity::class.java))
            activity.finish()

        }
        refuse_tv?.setOnClickListener {
            activity.finish()
        }
        tips_tv?.movementMethod = LinkMovementMethod.getInstance()
        tips_tv?.text = ZxSpanTool.getHighlightSpan(
                ZxSpanTool.getClickSpan("请您阅读完整的\n《用户协议》与《隐私政策》",
                        ZxSpanTool.OnTextClick { text, startIndex ->
                            if (text == "《用户协议》"){
                                Tool.startWebActivity(activity, "http://www.shangbangzuan.com:81/user_agreement.html", "用户协议")
                            }else if (text == "《隐私政策》"){
                                Tool.startWebActivity(activity, "http://www.shangbangzuan.com:81/privacy_policy.html", "隐私政策")
                            }
                        },"《用户协议》","《隐私政策》"),activity.resources.getColor(R.color.blue_f8),"《用户协议》","《隐私政策》")
    }

    override fun getLayoutId() = R.layout.dialog_privacy
}